package model

import (
	"encoding/json"
	"time"
)

var TableNameBucket = "bucket"

const (
	LocalDriver = "local"
	CosDriver   = "cos"
)

// Bucket mapped from table <sys_bucket>
type Bucket struct {
	ID         int64     `gorm:"column:id;primaryKey;autoIncrement:true" json:"id"`
	Name       string    `gorm:"column:name;not null;comment:Bucket名称" json:"name"` // Bucket名称
	Remark     string    `gorm:"column:remark;not null;comment:备注" json:"remark"`
	Driver     string    `gorm:"column:driver;not null;default:local;comment:local" json:"driver"`           // local
	Config     string    `gorm:"column:config;comment:配置" json:"config"`                                     // 配置
	CreateTime time.Time `gorm:"column:create_time;not null;comment:创建时间;autoCreateTime" json:"create_time"` // 创建时间
	UpdateTime time.Time `gorm:"column:update_time;not null;comment:更新时间;autoUpdateTime" json:"update_time"` // 更新时间
}

func (b *Bucket) GetConfig() map[string]string {
	cfg := make(map[string]string)
	_ = json.Unmarshal([]byte(b.Config), &cfg)
	return cfg
}

// TableName SysBucket's table name
func (*Bucket) TableName() string {
	return TableNameBucket
}
